package cn.xiaoxiang.basic.controller;

import cn.xiaoxiang.basic.dto.*;
import cn.xiaoxiang.basic.service.LoginService;
import cn.xiaoxiang.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;
    @PostMapping("/account")
    public AjaxResult getAccount(@RequestBody @Valid LoginDto dto)  {
        HashMap<String,Object> map= loginService.getAccount(dto);
        return AjaxResult.me().success(map);
    }
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid SmsCodeLoginDto sms)  {
        HashMap<String,Object> map2= loginService.smsCode(sms);
        return AjaxResult.me().success(map2);
    }

    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody @Valid WechatDto dto)  {

        return loginService.wechat(dto);
    }
    @PostMapping("/wechat/binder")
    public AjaxResult binder(@RequestBody @Valid BinderDto dto)  {

        HashMap<String,Object> map=loginService.binder(dto);
        return AjaxResult.me().success(map);
    }
}
